package online.flowerinsnow.minecraft.bukkit.testffa.manager;

import online.flowerinsnow.minecraft.bukkit.testffa.util.ItemStackFactory;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;

public class KitManager {
    private KitManager() {
    }

    public static void clearInventory(@NotNull Player player) {
        for (int i = 0; i < 40; i++) {
            player.getInventory().setItem(i, null);
        }
    }

    public static void getSpawnKit(@NotNull Player player) {
        clearInventory(player);
        player.getInventory().setItem(0, new ItemStackFactory(Material.DIAMOND_CHESTPLATE)
                .setDisplayName("&b获得装备 &7(右键点击)", true)
                .toItemStack());

        player.getInventory().setItem(8, new ItemStackFactory(Material.BOOK)
                .setDisplayName("&e编辑Kit &7(右键点击)", true)
                .toItemStack());
    }

    public static void getCombatKit(@NotNull Player player) {
        clearInventory(player);
        player.getInventory().setHelmet(new ItemStackFactory(Material.DIAMOND_HELMET)
                .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true)
                .unbreakable()
                .toItemStack());
        player.getInventory().setChestplate(new ItemStackFactory(Material.DIAMOND_CHESTPLATE)
                .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true)
                .unbreakable()
                .toItemStack());
        player.getInventory().setLeggings(new ItemStackFactory(Material.DIAMOND_LEGGINGS)
                .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true)
                .unbreakable()
                .toItemStack());
        player.getInventory().setBoots(new ItemStackFactory(Material.DIAMOND_BOOTS)
                .addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2, true)
                .unbreakable()
                .toItemStack());

        ConfigurationSection config = PlayerKitManager.getPlayerKit(player);
        if (config == null) {
            player.kickPlayer("§c您的数据加载错误 若该问题持续出现 请联系管理员");
            return;
        }
        for (int i = 0; i < 36; i++) {
            player.getInventory().setItem(i, config.getItemStack(Integer.toString(i)));
        }

        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999, 1));
    }
}
